package com.gzxxgl.user;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.gzxxgl.enu.EnumMsg;
import com.gzxxgl.enu.TableSequence;
import com.gzxxgl.model.data.User;
import com.gzxxgl.model.data.UserInfo;
import com.gzxxgl.model.data.UserInfoChange;
import com.gzxxgl.model.data.UserOrganiz;
import com.gzxxgl.model.data.UserReward;
import com.gzxxgl.model.data.UserSalary;
import com.gzxxgl.model.data.UserSalaryData;
import com.gzxxgl.util.BASE64encry;
import com.gzxxgl.util.DateUtil;
import com.gzxxgl.util.ExcelExportUtil;
import com.gzxxgl.util.ExcelImportUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.upload.UploadFile;

public class UserController extends Controller {

/*	public void index() {

		User u = new User();
		boolean flag = u.set("gid", TableSequence.user_id_sequence.name() + TableSequence.val)
				.set("loginname", "admin")
				.set("realname", "admin")
				.set("pasword", "123").save();

		if (flag)
			renderJson(EnumMsg.SUCCESS);

		renderJson(EnumMsg.ERR);
	}*/

	public void editpsd(){
	
		setAttr("dlsjjl", "修改密码");
		Map<String, Object> m = new HashMap<>();
		m.put("msg", EnumMsg.ERR.name());
		User cu = getSessionAttr("currentuser");
		String s ;
		boolean flag=false;
		if(cu !=null){
			s = cu.getPasword();
		    if(s.equals(BASE64encry.encry(getPara("opwd")))){
		    	User u = User.dao.findById(cu.getGid());
		    	u.setPasword(BASE64encry.encry(getPara("npwd")));
		    	u.set("isnew", 1);
		    	flag = u.update();
		    	if(flag){
		    		m.put("msg", EnumMsg.SUCCESS.name());
		    	}
		    }	
		}
		m.put("flag", flag);
		renderJson(m);
	}
	
	public void unlock(){
		setAttr("dlsjjl", "解除锁屏");
		Map<String, Object> m = new HashMap<>();
		m.put("msg", EnumMsg.ERR.name());
		User u = getSessionAttr("currentuser");
		boolean flag = false;
		if(u != null ){
			if( u.getPasword().equals(BASE64encry.encry(getPara("password")))){
			flag = true;
			m.put("msg", EnumMsg.SUCCESS);
			}
		}else{
			//session过期登出
			m.put("msg", "session过期");
			forwardAction("/logout");
		}
		m.put("success", flag);
		
		renderJson(m);
		
	}
	public void finduser(){
		setAttr("dlsjjl", "查看个人信息");
		Map<String, Object> m = new HashMap<>();
		
		
		try {
			UserInfo ui = UserInfo.dao.findById(getPara("id"));
			if(ui !=null){
				m.put("msg",  EnumMsg.SUCCESS);
				m.put("flag", true);
				m.put("_obj", ui);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			m.put("flag", false);
			m.put("msg", EnumMsg.ERR.name());
		}
		renderJson(m);
	}
	public void updateself(){
		setAttr("dlsjjl", "更新个人信息");
		Map<String, Object> m = new HashMap<>();
		m.put("msg", EnumMsg.ERR.name());
		
		UserInfoChange uic = getModel(UserInfoChange.class, "");
		boolean flag = uic.set("", TableSequence.user_info_change_id_sequence.name()+TableSequence.val)
				.set("gdate", new Timestamp(System.currentTimeMillis())).save();
		if(flag) {
			m.put("msg",  EnumMsg.SUCCESS);
		}
		m.put("flag", flag);
		renderJson(m);
	}
	@Before(Tx.class)
	public void approveself(){
		setAttr("dlsjjl", "审批个人信息");
		Map<String, Object> m = new HashMap<>();
		m.put("msg", EnumMsg.ERR.name());
		
		UserInfoChange uic = UserInfoChange.dao.findById(getPara("id"));
		UserInfo ui =  new UserInfo();
		 try {
			 
			BeanUtils.copyProperties(ui, uic);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		 
		 boolean flag = ui.save(),
				 flag1 = uic.set("isdelete", 0).update();
		 
		 if(flag && flag1){
			m.put("msg",  EnumMsg.SUCCESS);
		}
		m.put("flag", flag);
		renderJson(m);
		
	}
	@Before(Tx.class)//配置事务
	public void add() {

		setAttr("dlsjjl", "新增用户");
		
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		boolean flag,flagi,flags,flagr;
		//添加user
		User u = new User();
		flag = u.set("gid", TableSequence.user_id_sequence.name() + TableSequence.val)
				.set("loginname", getPara("loginname")).set("realname", getPara("xm"))
				.set("pasword", BASE64encry.encry(getPara("password")))
				.set("organizid", getPara("gwid"))
				.set("right", getPara("right")).save();
		//添加user_info
		UserInfo ui = new UserInfo();
		
		 String csrq = getPara("sfzh").substring(6, 13);
		 csrq = DateUtil.getString(DateUtil.getDate("20160623","yyyyMMdd"),"yyyy-MM-dd");
		ui.set("infoid", TableSequence.user_info_id_sequence.name()+TableSequence.val)
				.set("ygbm", getPara("ygbm"))
				.set("xm", getPara("xm"))
				.set("xb", getPara("xb"))
				.set("mz", getPara("mz"))
				.set("jg", getPara("jg"))
				.set("gage", getPara("gage"))
				.set("sfzh", getPara("sfzh"))
				.set("xl", getPara("xl"))
				.set("xw", getPara("xw"))
				.set("zc", getPara("zc"))
				.set("zzmm", getPara("zzmm"))
				.set("hyzk", getPara("hyzk"))
				.set("rzrq", getPara("rzrq"))
				.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
				.set("szbmid", getPara("szbmid"))
				.set("gwmc", UserOrganiz.dao.querybmbh(getPara("gwid")))
				.set("gwid", getPara("gwid"))
				.set("gwlx", getPara("gwlx"))
				//.set("gwlxid", getPara("gwlx"))
				.set("ygxz", getPara("ygxz"))
				//.set("ygxzid", getPara("ygxz"))
				.set("lxdh", getPara("lxdh"))
				.set("xmmc", getPara("xmmc"))
				//.set("xmmcid", getPara("xmmc"))
				.set("gid", u.get("gid"))
				.set("zy", getPara("zy"))
				.set("zcdw",  getPara("zcdw"))
				.set("csrq", csrq);
		if(StrKit.notBlank(getPara("zp"))){
			ui.set("zp", getPara("zp"));
		}
		flagi = ui.save();
		//添加salary
		UserSalary sa = new UserSalary();
		 sa.set("salaryid", TableSequence.user_salary_id_sequence.name()+TableSequence.val)
				.set("ygbm", getPara("ygbm"))
				.set("xm", getPara("xm"))
				.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
				.set("gwlx", getPara("gwlx"))
				.set("ygxz", getPara("ygxz"))
				.set("rzrq", getPara("rzrq"))
				.set("gid", u.get("gid"))
				.set("xmmc",  getPara("xmmc"))
				//.set("xmmcid", getPara("xmmc"))
				.set("gw", UserOrganiz.dao.querybmbh(getPara("gwid")))
				//五险
				.set("ylbx", "217.84")
				.set("sybx", "8.17")
				.set("ylbxx", "54.46")
				.set("dbbx", "11.34")
				.set("dbbx", "11.34")
				
		 		.set("txbt", "100")
		  		.set("jtbt", "50");
		  		
		//		sa.set("gjj", "245");
				
		flags =sa.save();
		//添加reword
		UserReward re = new UserReward();
		re.set("rewardid", TableSequence.user_rewardid_id_sequence.name()+TableSequence.val)
			.set("ygbm", getPara("ygbm"))
			.set("xm", getPara("xm"))
			.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
			.set("gwlx", getPara("gwlx"))
			.set("ygxz", getPara("ygxz"))
			.set("xmmc", getPara("xmmc"))
			.set("gid", u.getGid());
		flagr = re.save();
		if (flag && flagi && flags && flagr) {
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
		}
		renderJson(m);

	}
	@Before(Tx.class)//配置事务
	public void update() {

		setAttr("dlsjjl", "更新用户信息");
		
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		boolean flag,flagi,flags,flagr;
		User u = User.dao.findById(getPara("id"));
		u.set("loginname", getPara("loginname")).set("realname", getPara("xm"))
				.set("organizid", getPara("gwmc"))
				.set("right", getPara("right"));
		if(StrKit.notBlank(getPara("password"))){
			u.set("pasword", BASE64encry.encry(getPara("password")));
		}
		 flag = u.update();
		//身份证号解析出生日期
		 String csrq = getPara("sfzh").substring(6, 13);
		 csrq = DateUtil.getString(DateUtil.getDate("20160623","yyyyMMdd"),"yyyy-MM-dd");
		 
		UserInfo ui = UserInfo.dao.querybygid(getParaToInt("id"));
		 flagi = ui.set("ygbm", getPara("ygbm"))
				.set("xm", getPara("xm"))
				.set("xb", getPara("xb"))
				.set("mz", getPara("mz"))
				.set("jg", getPara("jg"))
				.set("gage", getPara("gage"))
				.set("sfzh", getPara("sfzh"))
				.set("xl", getPara("xl"))
				.set("xw", getPara("xw"))
				.set("zc", getPara("zc"))
				.set("zzmm", getPara("zzmm"))
				.set("hyzk", getPara("hyzk"))
				.set("rzrq", getPara("rzrq"))
				.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
				.set("szbmid", getPara("szbmid"))
				.set("gwmc", UserOrganiz.dao.querybmbh(getPara("gwid")))
				.set("gwid", getPara("gwid"))
				.set("gwlx", getPara("gwlx"))
				//.set("gwlxid", getPara("gwlx"))
				.set("ygxz", getPara("ygxz"))
			//	.set("ygxzid", getPara("ygxz"))
				.set("xmmc", getPara("xmmc"))
			//	.set("xmmcid", getPara("xmmc"))
				.set("lxdh", getPara("lxdh"))
				.set("zp", getPara("zp"))
				.set("zy", getPara("zy"))
				.set("zcdw",  getPara("zcdw"))
				.set("csrq", csrq)
				.update();
		 
		 UserSalary sa = UserSalary.dao.querybygid(getParaToInt("id"));
		 flags = sa.set("ygbm", getPara("ygbm"))
				.set("xm", getPara("xm"))
				.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
				.set("gwlx",getPara("gwlx"))
				.set("ygxz", getPara("ygxz"))
				.set("rzrq", getPara("rzrq"))
				.set("gid", u.get("gid"))
				.set("xmmc", getPara("xmmc"))
				//.set("xmmcid", getPara("xmmc"))
				.set("gw", UserOrganiz.dao.querybmbh(getPara("gwid"))).update();
		 
		 UserReward re = UserReward.dao.querybygid(getParaToInt("id"));
		 if(re == null){
			 flagr = true;
		 }else{
			 flagr = re.set("ygbm", getPara("ygbm"))
						.set("xm", getPara("xm"))
						.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")))
						.set("gwlx", getPara("gwlx"))
						.set("ygxz", getPara("ygxz"))
						.set("xmmc", getPara("xmmc"))
						.update();
		 }
		
		if (flag && flagi && flags && flagr) {
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
		}
		renderJson(m);
		
	}
	@Before(Tx.class)
	public void delete() {

		setAttr("dlsjjl", "删除用户");
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		User u = User.dao.findById(getPara("id"));
		UserInfo ui = UserInfo.dao.querybygid(getParaToInt("id"));
		boolean flag = u.set("isdelete", 1).update();
		boolean flag1 = ui.set("isdelete", 1).update();
		if (flag && flag1) {
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
		}
		renderJson(m);
	}
	public void findusers(){

		setAttr("dlsjjl", "查看所有用户 ");
		Map<String, Object> m = new HashMap<>();
		Map<String, String> con = new HashMap<>();
		m.put("code", 0);
		m.put("msg", EnumMsg.SUCCESS);
		
		Page<User> page = null;
		try {
			con.put("xm", getPara("xm"));
			page = User.dao.queryUsers(getParaToInt("pageIndex"), getParaToInt("pageSize"), con);
		
		} catch (Exception e) {
			e.printStackTrace();
			m.put("code", 1);
			m.put("msg", EnumMsg.ERR);
		}
		m.put("count", page.getTotalRow());
		m.put("list", page);
		
		renderJson(m);
		
		
	}
	public void finduserchanges(){

		setAttr("dlsjjl", "查看用户的修改申请 ");
		Map<String, Object> m = new HashMap<>();
		Map<String, String> con = new HashMap<>();
		m.put("code", 0);
		m.put("msg", EnumMsg.SUCCESS);
		
		Page<UserInfoChange> page = null;
		try {
			con.put("xm", getPara("xm"));
			con.put("xb", getPara("xb"));
			con.put("xl", getPara("xl"));
			con.put("mz", getPara("mz"));
			con.put("zjmm", getPara("zjmm"));
			con.put("szbmid", getPara("szbmid"));
			page = UserInfoChange.dao.queryuserchanges(getParaToInt("pageIndex"), getParaToInt("pageSize"), con);
		
		} catch (Exception e) {
			e.printStackTrace();
			m.put("code", 1);
			m.put("msg", EnumMsg.ERR);
		}
		m.put("count", page.getTotalRow());
		m.put("list", page);
		
		renderJson(m);
		
		
	}
	public void adduserinfochange(){
		setAttr("dlsjjl", "提交用户修改信息");
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		UserInfoChange r = getModel(UserInfoChange.class, "");
		UserInfoChange uc = UserInfoChange.dao.querybyinfoid(r.get("infoid"));
		r.set("cdate", new Timestamp(System.currentTimeMillis()));
		r.set("szbm", UserOrganiz.dao.querybmbh(getPara("szbmid")));
		r.set("gwmc", UserOrganiz.dao.querybmbh(getPara("gwid")));
		boolean flag = false;
		if(uc == null){
			r.set("changeid", TableSequence.user_info_change_id_sequence.name()+TableSequence.val);
			flag = r.save();
		}else{
			r.set("changeid", uc.getChangeid());
			flag = r.update();
		}
		if(flag){
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
		}
		renderJson(m);
	}
	@Before(Tx.class)
	public void userchangeapprove(){
		setAttr("dlsjjl", "审批 ");
		Map<String, Object> m = new HashMap<>();
		
		String ids = getPara("ids");
		Record r1 = null;
		UserSalary rs = null;
		User user = null;
		UserReward reward = null;
		UserInfoChange uc = null;
		
		List<Record> lr = new ArrayList<>();
		List<UserInfoChange> lu = new ArrayList<>();
		List<User> luser = new ArrayList<>();
		List<UserSalary> lsalary = new ArrayList<>();
		List<UserReward> lreward = new ArrayList<>();
		
		for(String id : ids.split(",")){
			if(StrKit.notBlank(id)){
			uc = UserInfoChange.dao.findById(id);
			r1 = Db.findById("g_user_info_change", "changeid", id);
			String gid = r1.getBigDecimal("gid")+"";
			rs = UserSalary.dao.querybygid(gid);
			user = User.dao.findById(gid);
			reward = UserReward.dao.querybygid(gid);
			
			uc.set("isdelete", 1);
			lu.add(uc);
			
			r1.remove("changeid");
			r1.remove("cdate");
			r1.remove("gdate");
			lr.add(r1);
			
			rs.set("ygbm", r1.get("ygbm"));
			rs.set("xm", r1.get("xm"));
			rs.set("szbm", r1.get("szbm"));
			rs.set("gwlx", r1.get("gwlx"));
			rs.set("ygxz", r1.get("ygxz"));
			rs.set("xmmc", r1.get("xmmc"));
			rs.set("gw", r1.get("gwmc"));
			
			lsalary.add(rs);
			
			reward.set("ygbm", r1.get("ygbm"));
			reward.set("xm", r1.get("xm"));
			reward.set("szbm", r1.get("szbm"));
			reward.set("gwlx", r1.get("gwlx"));
			reward.set("ygxz", r1.get("ygxz"));
			reward.set("xmmc", r1.get("xmmc"));
			
			lreward.add(reward);
			
			user.set("organizid", r1.get("szbmid"));
			
			luser.add(user);
			
			
			}
		}
		Db.batchUpdate("g_user_info", "infoid", lr, 100);
		Db.batchUpdate(lu,100);
		Db.batchUpdate(luser,100);
		Db.batchUpdate(lreward,100);
		Db.batchUpdate(lsalary,100);
		
		
		m.put("flag", true);
		m.put("msg", EnumMsg.SUCCESS);
		
		renderJson(m);
	}
	public void findusersalarys(){


		setAttr("dlsjjl", "查看用户的工资明细");
		Map<String, Object> m = new HashMap<>();
		Map<String, String> con = new HashMap<>();
		m.put("code", 0);
		m.put("msg", EnumMsg.SUCCESS);
		
		Page<User> page = null;
		try {
			con.put("xm", getPara("xm"));
			page = User.dao.queryUserSalarys(getParaToInt("pageIndex"), getParaToInt("pageSize"), con);
		
		} catch (Exception e) {
			e.printStackTrace();
			m.put("code", 1);
			m.put("msg", EnumMsg.ERR);
		}
		m.put("count", page.getTotalRow());
		m.put("list", page);
		
		renderJson(m);	
		
	}
	public void findusersalarydatas(){
		setAttr("dlsjjl", "查看用户的工资统计");
		Map<String, Object> m = new HashMap<>();
		Map<String, String> con = new HashMap<>();
		m.put("code", 0);
		m.put("msg", EnumMsg.SUCCESS);
		
		Page<UserSalaryData> page = null;
		try {
			con.put("xm", getPara("xm"));
			con.put("gyear", getPara("gyear"));
			con.put("gmonth", getPara("gmonth"));
			con.put("xb", getPara("xb"));
			con.put("xl", getPara("xl"));
			con.put("mz", getPara("mz"));
			con.put("zzmm", getPara("zzmm"));
			con.put("szbmid", getPara("szbm"));
			con.put("start", getPara("start"));
			con.put("end", getPara("end"));
			
			User u = getSessionAttr("currentuser");
			if("15".equals(u.get("right"))){
				con.put("szbmid",u.get("organizid")+"");
			}
			if("16".equals(u.get("right"))){
				con.put("gid", u.get("gid")+"");
			}
			page = User.dao.queryUserSalarydatas(getParaToInt("pageIndex"), getParaToInt("pageSize"), con);
		
		} catch (Exception e) {
			e.printStackTrace();
			m.put("code", 1);
			m.put("msg", EnumMsg.ERR);
		}
		m.put("count", page.getTotalRow());
		m.put("list", page);
		
		renderJson(m);	
		
	}
	public void exportexcel(){

		setAttr("dlsjjl", "导出用户信息");
		String Sql = "select * from g_user_info where isdelete= 0 order by infoid";
		String columns1 = getPara("cols");
		String tabname = "";
		String titlename = "";
		String comment1 = "";
		try {
			comment1 = getPara("coms");//new String(getPara("coms").toString().getBytes("iso8859_1"),"utf-8");
			tabname = getPara("tabname");//new String(getPara("tabname").toString().getBytes("iso8859_1"),"utf-8");
			titlename = getPara("titlename");//new String(getPara("titlename").toString().getBytes("iso8859_1"),"utf-8");	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String ids = getPara("names");
		Map<String, String> m = new LinkedHashMap<>();
		for(int i=0;i<columns1.split(",").length;i++){
			m.put(columns1.split(",")[i].trim(), comment1.split(",")[i].trim());
		}
		renderFile(ExcelExportUtil._saveFile(m, "g_user_info,infoid", ids, new File(PathKit.getWebRootPath()+"\\temp\\"+tabname+".xls"), titlename, Sql));
	}
	
	@Before(Tx.class)
	public void importexcel(){

		setAttr("dlsjjl", "导入用户信息");
		UploadFile f = 	getFile("filename");
		//检索文件数据
		Map<String, Object> map = ExcelImportUtil.ReadExcel2003(f.getFile(), null, 22);
		Object[][] o = (Object[][]) map.get("para");
		List<Record> ls, ls1;
		Record r,r1;
		if((Integer)map.get("code") == 0 && o.length>0){
			
			//数据入库
			ls  = new ArrayList<>(); //user
			ls1  = new ArrayList<>(); //userinfo
			
			
			String columns1 = "INFOID, YGBM, SZBM, SZBMID, GWMC, GWLX, YGXZ, XMMC, ZCDW, XM, XB, MZ, GAGE, JG, ZZMM, HYZK, XL, ZY, XW, SFZH, LXDH, RZRQ, GID";
		
			for(int i=0; i<o.length;i++){
				r = new Record();
				r1 = new Record();
				r.set("gid", o[i][0]);
				r.set("loginname", o[i][19]);
				r.set("realname", o[i][9]);
				r.set("pasword", BASE64encry.encry("123456"));
				r.set("organizid", o[i][3]);
				r.set("right", 16);
				
				for(int j=0; j<columns1.split(",").length; j++){
					String s=columns1.split(",")[j].trim();
					if("GID".equals(s)){
						r1.set(s, o[i][0]);
					}else{
						r1.set(s, (o[i][j]+"").trim());
					}
				}
				ls.add(r);
				ls1.add(r1);
			}
			
			@SuppressWarnings("unused")
			int[] ret = null,ret1 = null ;
			try {
				ret =  Db.batchSave("g_user", ls, 100);
				ret1 = Db.batchSave("g_user_info", ls1, 100);
			
			} catch (Exception e) {
				e.printStackTrace();
				System.out.println();
			}finally{
				int s = 0, l = 0;
				for (int i = 0; i < ret.length; i++)
					if (ret[i] >= 0 )
						s++;
					else if(ret[i] >= -2)
						s++;
					else
						l++;
				map.put("success", s);
				map.put("msg", "导入成功，总"+ret.length+"共导入"+s+"行数据，丢失"+l+"行数据 ");
			}
		}
		
		renderJson(map);
	}
	public void salaryimportexcel(){

		setAttr("dlsjjl", "导入工资信息");
		UploadFile f = 	getFile("filename");
		//检索文件数据
		Map<String, Object> map = ExcelImportUtil.ReadExcel2003(f.getFile(), null, 31);
		
		Object[][] o = (Object[][]) map.get("para");
		
		String columns = "SALARYID, YGBM, XM, SZBM, GW, GWLX, YGXZ, XMMC, RZRQ, GJ, GJGZ, GLGZ, ZYZGBT, "
				+ "TXBT, JTBT, CCBT, YBBT, JBGZ, SGBT, QTBT, YFGZ, JXKHGZ, YLBX, SYBX, YLBXX, DBBX, GJJ, "
				+ "GRSDS, GRKK, SFGZ, CZ, GID";
		
		String[] columnsl = columns.split(",");
		if((Integer)map.get("code") == 0 && o.length>0){
		Integer olength = o.length,
				collength =columnsl.length;
		
		List<Record> ls,ls2;
		Record r,r2;
		if((Integer)map.get("code") == 0 && o.length>0){
			//数据入库
			ls  = new ArrayList<>();
			ls2  = new ArrayList<>();
		   for(int i=0;i<olength;i++){
			   r = new Record();
			   r2 = new Record();
			   
			   r2.set("rewardid", o[i][0]);
			   r2.set("gid", o[i][0]);
			   r2.set("YGBM", o[i][1]);
			   r2.set("xm", o[i][2]);
			   r2.set("SZBM", o[i][3]);
			   r2.set("GWLX", o[i][5]);
			   r2.set("YGXZ", o[i][6]);
			   r2.set("XMMC", o[i][7]);
			   
			   for(int j=0;j<collength;j++){
				   if("GID".equals(columnsl[j].trim())){
					   r.set(columnsl[j].trim(), o[i][0]);
				   }else{
					   r.set(columnsl[j].trim(), o[i][j]);
				   }
			   }
			   ls.add(r);
			   ls2.add(r2);
		   }
		   
		   @SuppressWarnings("unused")
		int[] ret = null, ret2 = null;
			try {
			    ret = Db.batchSave("g_user_salary", ls, 100);
			    ret2 = Db.batchSave("g_user_reward", ls2, 100);
			   	}catch(Exception e){
				e.printStackTrace();
			}finally {
				 int s = 0, l = 0;
				 for (int i = 0; i < ret.length; i++)
						if (ret[i] >= 0 )
							s++;
						else if(ret[i] >= -2)
							s++;
						else
							l++;
					map = new HashMap<String, Object>();
					map.put("success", true);
					map.put("msg", "导入成功，总"+ret.length+"共导入"+s+"行数据，丢失"+l+"行数据 ");
			}
		}
		}
		map.put("paras", null);
		
		renderJson(map);
	}
	public void salaryexplortexcel(){

		setAttr("dlsjjl", "导出工资信息");
		String Sql = "select * from g_user_salary where isdelete= 0 ";
		String columns1 = "SALARYID , YGBM, XM, SZBM, GW, GWLX, YGXZ, XMMC, RZRQ, GJ, GJGZ, GLGZ, ZYZGBT, "
				+ "TXBT, JTBT, CCBT, YBBT, JBGZ, SGBT, QTBT, YFGZ, JXKHGZ, YLBX, SYBX, YLBXX, DBBX, GJJ, "
				+ "GRSDS, GRKK, SFGZ, CZ";
		String comment1 = "序号, 工号 , 姓名,  所在部门,  岗位, 岗位类型, 用工性质,  负责项目, 入职日期, 从属岗级, 岗级工资, 工龄补贴, "
				+ "专业资格补贴, 通讯 补助, 交通补助,	出车补贴,	夜班补贴, 加班,	适岗补贴,	补发, 应发工资,	绩效考核工资, 养老保险, "
				+ "失业保险, 医疗保险,	大病医疗,	公积金, 个税, 个人扣款, 实发工资,	存折";
		String[] collength = columns1.split(","),comlength = comment1.split(",");
		Map<String, String> m = new LinkedHashMap<>();
		for(int i=0;i<collength.length; i++){
			m.put(collength[i].trim(), comlength[i].trim());
		}
		renderFile(ExcelExportUtil.saveFile(m, Sql, new File(PathKit.getWebRootPath()+"\\temp\\员工工资基本信息.xls"),"员工工资基本信息"));
		
	}
	public void salarydataexplortexcel(){
		setAttr("dlsjjl", "导出工资条信息");
		Integer[] time = DateUtil.getDate(new Date());
		String Sql = "select * from g_user_salary_data d where d.gyear="+time[0]+"and d.gmonth="+time[1]+"and d.isdelete=0 order by d.gdate";
		String columns1 = getPara("cols");
		String tabname = "";
		String titlename = "";
		String comment1 = "";
		try {
			comment1 = getPara("coms");//new String(getPara("coms").toString().getBytes("iso8859_1"),"utf-8");
			tabname = getPara("tabname");//new String(getPara("tabname").toString().getBytes("iso8859_1"),"utf-8");
			titlename = getPara("titlename");//new String(getPara("titlename").toString().getBytes("iso8859_1"),"utf-8");	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String ids = getPara("names");
		Map<String, String> m = new LinkedHashMap<>();
		for(int i=0;i<columns1.split(",").length;i++){
			m.put(columns1.split(",")[i].trim(), comment1.split(",")[i].trim());
		}
		renderFile(ExcelExportUtil._saveFile(m, "g_user_salary_data,salarydataid", ids, new File(PathKit.getWebRootPath()+"\\temp\\"+tabname+".xls"), titlename, Sql));
		
	}
	@SuppressWarnings("unused")
	private static String toStr(String[] a){
		String str = "";
		for(int i=0; i<a.length;i++){
			if(i==a.length-1){
				str += a[i];
			}else{
			str += a[i]+",";}
		}
		return str;
	}
	
	public void lookpwd(){
		setAttr("dlsjjl", "查看密码");
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		if(StrKit.notBlank(getPara("pwd"))){
			String s = BASE64encry.decry(getPara("pwd"));
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
			m.put("obj", s);
		}
		renderJson(m);
	}

	public void colsandcoms(){
		setAttr("dlsjjl", "查看"+getPara("tab")+"列名");
		Map<String, Object> m = new HashMap<>();
		m.put("flag", false);
		m.put("msg", EnumMsg.ERR);
		
		List<Record> l = Db.find("select * from user_col_comments t where t.table_name= ? ", getPara("tab"));
		
		if(l.size()>0){
			m.put("flag", true);
			m.put("msg", EnumMsg.SUCCESS);
			m.put("list", l);
		}
		
		renderJson(m);
	}
}
